package com.deer.wms.base.system.web.box;

import com.deer.wms.base.system.model.box.AreaBoxItemDto;
import com.deer.wms.base.system.model.box.AreaBoxItemHistory;
import com.deer.wms.base.system.model.box.BoxTurnover;
import com.deer.wms.base.system.service.box.AreaBoxItemHistoryService;
import com.deer.wms.base.system.service.box.AreaBoxItemService;
import com.deer.wms.common.core.controller.BaseController;
import com.deer.wms.common.core.page.TableDataInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
/***
 *暂存区历史报表
 * @author 李帅辰
 * @date 2020/10/22 17:57 
 * @return 
 */
@Controller
@RequestMapping("/out/AreaBoxItemHistory")
public class AreaBoxItemHistoryController extends BaseController {
    private String prefix = "out/AreaBoxItemHistory";
    @Autowired
    private AreaBoxItemHistoryService areaBoxItemHistoryService;

    /**
     * 跳转页面
     * @return
     */
    @RequiresPermissions("out:AreaBoxItemHistory:view")
    @GetMapping("/page")
    public String workMaster()
    {
        return prefix + "/AreaBoxItemHistory";
    }

    /*周转率*/
    //@RequiresPermissions("out:AreaBoxItemHistory:list")
    @PostMapping("/findList")
    @ResponseBody
    public TableDataInfo findList(BoxTurnover boxTurnover) {
        startPage();
        List<BoxTurnover> list = areaBoxItemHistoryService.selectBoxTurnoverList(boxTurnover);
        return getDataTable(list);
    }
    /*储存每天周转率所需要的数据*/
    @Scheduled(cron = "0 0 0 * * ?")
    //@Scheduled(cron = "*/5 * * * * ?")
    public void saveTurnoverMSG(){
        //1.物料当天出/入/库存
        List<BoxTurnover> boxTurnoverList = areaBoxItemHistoryService.findBoxTurnoverList();
        boxTurnoverList.forEach(boxTurnover->{
            //2.保存数据
            areaBoxItemHistoryService.saveTurnoverMSG(boxTurnover);
        });
    }


}
